<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>主题更换管理</title>
    <link rel="shortcut icon" href="/images/index/logo.ico">
    <style>
        .refresh, .search {
            display: inline-block;
            float: right;
        }

        .search {
            margin-right: 40%;
            cursor: pointer;
        }
    </style>
</head>
<body>
<div class="refresh">
    <button class="btn btn-info refresh" title="刷新" data-url="/themeExamine/admin/listTheme"><span
            class="glyphicon glyphicon-refresh"></span></button>
</div>
<div class="search">
    <form class="form-inline">
        <div class="form-group">
            <div class="input-group">
                <input type="text" class="form-control" id="type" placeholder="模糊查询">
                <div class="input-group-addon"><span class="glyphicon glyphicon-glass"></span> 查询</div>
            </div>
        </div>
    </form>
</div>
<div class="">
    <ol class="breadcrumb">
        <li><a href="javascript:;">账号管理</a></li>
        <li class="active">主题统计<span class="badge">${dataMap.size()}</span></li>
    </ol>
</div>

<div class="banner_show">
    <table class="table table-bordered table-responsive">
        <tr>
            <th>id</th>
            <th>分类</th>
            <th>上传者</th>
            <th>主题名称</th>
            <th>上传时间</th>
            <th>状态</th>
            <th>操作</th>
        </tr>

        <c:forEach var="data" items="${dataMap}">
            <tr>
                <td class="id">${data.id}</td>
                <td>${data.cname}</td>
                <td>${data.uname}</td>
                <td>${data.title}</td>
                <td><fmt:formatDate value="${data.date}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                <c:if test="${data.state==false}">
                    <td data-status="0" class="status">未使用</td>
                </c:if>
                <c:if test="${data.state}">
                    <td data-status="1" class="status">使用中</td>
                </c:if>
                <td class="operate ">
                    <button class=" btn btn-info banner_active start_stop" data-state="${data.state}"><c:if
                            test="${data.state}">下线</c:if><c:if
                            test="${data.state==false}">启用</c:if></button>
                    <button class=" btn btn-info top">上移</button>
                    <button class=" btn btn-primary down">下移</button>
                    <a class=" btn btn-link lookfor"
                       href="/themeScreenshot/user/lists?tid=${data.id}&bimage=${data.bimage}" target="_blank">
                        浏览
                    </a>
                    <c:if test="${data.state==false}">
                        <button class=" btn btn-danger delete">删除</button>
                    </c:if>

                </td>
            </tr>
        </c:forEach>

    </table>
</div>
<button class="btn btn-primary save" data-url="theme_add.html" style="margin-right: 20px;">
    <span class="glyphicon glyphicon-upload"></span> 提交
</button>
<script>
    $(document).ready(function () {
        $('.refresh').click(function () {
            var scope = $(this);
            $('.content_right').load(scope.attr('data-url'));
            toast_text('刷新成功', 600);
        });
//      禁用函数监听
        function forbid_click() {
            $('.start_stop').unbind('click').click(function () {
                var scope = $(this);
                start_top('/themeExamine/admin/useExamine', $(this).parent().siblings('.id').text(), $(this).attr('data-state'), '/themeExamine/admin/listTheme');
            });
        }
        forbid_click();

        //分类模糊查询表格中的内容
        $("#type").keyup(function () {
            if ($.trim($('#type').val()) == '全部') {
                $("table tr:gt(0)").show();
            } else {
                $("table tr:gt(0)").hide();
                var $d = $("table tr:gt(0)").filter(":contains('" + $.trim($("#type").val()) + "')");
                $d.show();
            }
        });


        bind_click_top();
        bind_click_bottom();

        function bind_click_top() {
            $('.top').unbind('click').click(function () {
                var index = $(this).parent().parent().index();
                if (index !== 1) {
                    var html_1 = $(this).parent().parent().prev().html();
                    var html_2 = $(this).parent().parent().html();
                    $(this).parent().parent().prev().html(html_2);
                    $(this).parent().parent().html(html_1);
                    bind_click_top();
                    bind_click_bottom();
                    forbid_click();
                    delete_click();
                }
            });
        }

//      下移的函数
        function bind_click_bottom() {
            $('.down').unbind('click').click(function () {
                var index = $(this).parent().parent().index();
                if (index !== $('.table tr').length - 1) {
                    var html_1 = $(this).parent().parent().next().html();
                    var html_2 = $(this).parent().parent().html();
                    $(this).parent().parent().next().html(html_2);
                    $(this).parent().parent().html(html_1);
                    bind_click_bottom();
                    bind_click_top();
                    forbid_click();
                    delete_click();

                }
            });
        }

        function delete_click() {
            $('.delete').unbind('click').click(function () {
                custom_modal('你确定要删除该主题？');
                var scope = $(this);
                $('.modal_footer button').eq(0).unbind().click(function () {
                    $.post("/themeExamine/admin/deleteTheme", {
                        id: scope.parent().siblings('.id').text(),
                    }, function (data) {
                        if (data.code == 200) {
                            $('.modal_1').hide();
                            scope.parent().parent().remove();
                        }
                        toast_text(data.msg, 600);
                    });
                });
            });
        }
        delete_click();



//        提交
        var save_id = [];
        $('.save').click(function () {
            $('.table tr').each(function (index, elem) {
                if (index > 0) {
                    save_id.push($(elem).find('td').eq(0).text());
                }
            });

            $.post("/themeAdmin/user/softTheme", {id: save_id.join(",")}, function (data) {
                if (data.code == 200) {
                    toast_text(data.msg, 3000);
                }
            });
        });
    });

    //
</script>
</body>
</html>